package com.jyxd.web.controller.basic;

import com.jyxd.web.data.basic.BreatheSystemForm;
import com.jyxd.web.data.dto.HttpResult;
import com.jyxd.web.service.assessment.basic.BreatheSystemFormService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

import static com.jyxd.web.util.ExecuteUtil.errorIfEmpty;

@Api(tags = "呼吸系统相关接口")
@Controller
@RequestMapping(value = "/breatheSystemForm")
public class BreatheSystemFormController {

    @Autowired
    private BreatheSystemFormService breatheSystemFormService;

    @ApiOperation("新增呼吸系统数据")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult saveOrUpdate(@RequestBody BreatheSystemForm breatheSystemForm) {
        return breatheSystemFormService.saveOrUpdate(breatheSystemForm);
    }

    @ApiOperation("删除一条数据")
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult deleteById(@RequestBody Map<String, Object> map) {
        errorIfEmpty(map, "参数不存在");
        return breatheSystemFormService.deleteById((String) map.get("id"));
    }

    @ApiOperation("分页查询数据")
    @RequestMapping(value = "/getListPage", method = RequestMethod.POST)
    @ResponseBody
    public HttpResult getListPage(@RequestBody Map<String, Object> map) throws Exception {
        return breatheSystemFormService.getListPage(map);
    }
}
